
//-----------------MATRICES---------------
float4x4 xWorld: World;				
float4x4 xView: View;
float4x4 xProjection: Projection;


//-------------------TEXTURES--------------------

Texture xTexture;
sampler TextureSampler = sampler_state { texture = <xTexture> ;
    magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = mirror; AddressV = mirror;};
	
//-------------------LIGHTS--------------------
float4 xLightPosition0;
float4 xLightColor0;
float xLightPower0;

float4 xLightPosition1;
float4 xLightColor1;
float xLightPower1;

float4 xLightPosition2;
float4 xLightColor2;
float xLightPower2;

float4 xLightPosition3;
float4 xLightColor3;
float xLightPower3;

float4 xLightPosition4;
float4 xLightColor4;
float xLightPower4;

float4 xLightPosition5;
float4 xLightColor5;
float xLightPower5;

float xHelper;
//------------------- STRUCTS -------------------   


struct BufferToVertex
{
float3 Pos : POSITION;
float4 Normal : NORMAL;
float4 UV : TEXCOORD0;
};


struct VertexToPixel
{
float4 Pos:POSITION;
float4 Normal:TEXCOORD2;
float4 Pos3D:TEXCOORD1;
float4 UV:TEXCOORD0;
};


struct PixelToFrame
{
float4 Color:COLOR;
};





//---------------------- SHADERS ------------------------

VertexToPixel simplestVS(BufferToVertex IN)
{
  VertexToPixel OUT = (VertexToPixel)0;
  float4x4 WorldViewProj;
  
  WorldViewProj=mul(xWorld,xView);
  WorldViewProj=mul(WorldViewProj,xProjection);
  
  OUT.Normal=IN.Normal;
  OUT.Pos=mul(float4(IN.Pos.xyz,1.0), WorldViewProj);
  OUT.Pos3D=mul(float4(IN.Pos.xyz,1.0),xWorld);  
  
  OUT.UV=float4(IN.UV.xy,1.0,1.0);
  return OUT;
}

PixelToFrame simplestPS(VertexToPixel IN) 
{
PixelToFrame OUT = (PixelToFrame)0;

float4 LightVector0 = normalize(xLightPosition0-IN.Pos3D);
float4 LightVector1 = normalize(xLightPosition1-IN.Pos3D);
float4 LightVector2 = normalize(xLightPosition2-IN.Pos3D);
float4 LightVector3 = normalize(xLightPosition3-IN.Pos3D);
float4 LightVector4 = normalize(xLightPosition4-IN.Pos3D);
float4 LightVector5 = normalize(xLightPosition5-IN.Pos3D);

float LightIntensity0 = dot(LightVector0, IN.Normal) * xLightPower0;
float LightIntensity1 = dot(LightVector1, IN.Normal) * xLightPower1;
float LightIntensity2 = dot(LightVector2, IN.Normal) * xLightPower2;
float LightIntensity3 = dot(LightVector3, IN.Normal) * xLightPower3;
float LightIntensity4 = dot(LightVector4, IN.Normal) * xLightPower4;
float LightIntensity5 = dot(LightVector5, IN.Normal) * xLightPower5;

float a = LightIntensity0 + LightIntensity1 + LightIntensity2 + LightIntensity3 + LightIntensity4 + LightIntensity5;
//a = a / 6;
//OUT.Color = saturate(tex2D(TextureSampler, IN.UV) * a + xLightColor0 * LightIntensity0
//													+ xLightColor1 * LightIntensity1
//													+ xLightColor2 * LightIntensity2
//													+ xLightColor3 * LightIntensity3
//													+ xLightColor4 * LightIntensity4
//													+ xLightColor5 * LightIntensity5);
if (xHelper == 1.0)
{
	a = 1;
}										
OUT.Color = saturate(tex2D(TextureSampler, IN.UV) * a);
return OUT;
}

VertexToPixel normalsVS(BufferToVertex IN)
{
  VertexToPixel OUT = (VertexToPixel)0;
  float4x4 WorldViewProj;
  
  WorldViewProj=mul(xWorld,xView);
  WorldViewProj=mul(WorldViewProj,xProjection);
  
  OUT.Normal=IN.Normal;
  OUT.Pos=mul(float4(IN.Pos.xyz,1.0), WorldViewProj);
  
  return OUT;
}


PixelToFrame normalsPS(VertexToPixel IN) 
{
	PixelToFrame OUT = (PixelToFrame)0;

	OUT.Color=IN.Normal;
	return OUT;
}



// ------------ TECHNIQUES --------------

technique simplest{
	pass p0 {
		VertexShader = compile vs_3_0 simplestVS();
		PixelShader = compile ps_3_0 simplestPS();
	}
}

technique normals{
	pass p0 {
		VertexShader = compile vs_3_0 normalsVS();
		PixelShader = compile ps_3_0 normalsPS();
	}
}
